package com.qf.web.controller;

import com.alibaba.fastjson.JSONArray;
import com.qf.service.GoodTypeService;
import com.qf.service.impl.GoodTypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * projectName:myxiaomi
 * author:jww
 * time:2024/4/20 11:33
 * description:
 */
@WebServlet("/findGoodsType")
public class FindGoodsTypeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/json;charset=UTF-8");
        GoodTypeService goodsTypeService=new GoodTypeServiceImpl();
        List<String> names=goodsTypeService.findName();
        System.out.println(names);
        JSONArray jsonArray=new JSONArray();
        jsonArray.addAll(names);//将集合中所有数据存入jsonArray中
        response.getWriter().print(jsonArray);//相应页面一个数组
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}


